package org.example.mybatis3.service;

import org.example.mybatis3.entity.discriminator.*;
import org.example.mybatis3.mapper.VehicleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicleService {

    @Autowired
    private VehicleMapper vehicleMapper;

    public void displayVehicles() {
        List<Vehicle> vehicles = vehicleMapper.selectAllVehicles();

        for (Vehicle vehicle : vehicles) {
            System.out.println("Vehicle: " + vehicle.getMake() + " " + vehicle.getModel());

            // 根据车辆类型进行不同的处理
            switch (vehicle.getVehicleType()) {
                case 1: // Car
                    Car car = (Car) vehicle;
                    System.out.println("Doors: " + car.getDoors());
                    break;
                case 2: // Truck
                    Truck truck = (Truck) vehicle;
                    System.out.println("Cargo Capacity: " + truck.getCargoCapacity());
                    break;
                case 3: // Van
                    Van van = (Van) vehicle;
                    System.out.println("Seating Capacity: " + van.getSeatingCapacity());
                    break;
                case 4: // SUV
                    SUV suv = (SUV) vehicle;
                    System.out.println("4WD: " + suv.getIs4WD());
                    break;
            }
        }
    }
}

